<style lang="less">
	page{
		background-color: #F7F7F7;
		padding-bottom: 50upx;
	}
		
	.container{
		padding: 30upx 30upx 0;
		box-sizing: border-box;
		.head{
			background-color: #FFFFFF;
			border-radius: 12upx;
			padding-top: 28upx;
		}
	}
	.time_select {
		display: flex;
		align-items: center;
		padding: 0 30upx;
		box-sizing: border-box;
		.select {
			width: 280upx;
			height: 60upx;
			padding: 0 10upx;
			box-sizing: border-box;
			background: #FFFFFF;
			border: 1upx solid #DDDDDD;
			margin-right: 16upx;
			font-size: 26upx;
		}
		.time_select_txt{
			font-size: 20upx;
			font-weight: 500;
			color: #999999;
			line-height: 29upx;
		}
	}
	.head_data{
		margin-top: 26upx;
		display: flex;
		flex-wrap: wrap;
		.head_list{
			border-top: 1upx solid #EDEDED;
			border-right: 1upx solid #EDEDED;
			width: 25%;
			padding: 36upx 0;
			display: flex;
			flex-direction: column;
			align-items: center;
			box-sizing: border-box;
			&:nth-of-type(4n){
				border-right: none;
			}
			.head_list_num{
				font-size: 40upx;
				font-family: "DINCond";
				font-weight: 400;
				color: #333333;
				line-height: 48upx;
			}
			.head_list_txt{
				font-size: 20upx;
				font-weight: 500;
				color: #999999;
				line-height: 29upx;
			}
		}
	}
	.matter{
		background: #FFFFFF;
		box-shadow: 0px 2px 12px 0px rgba(175, 175, 175, 0.2);
		border-radius: 15upx;
	}
	.matter_title{
		padding: 26upx 30upx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1upx solid #EDEDED;
		.matter_title_fl{
			font-size: 30upx;
			font-weight: bold;
			color: #333333;
			line-height: 30upx;
		}
		.matter_title_fr{
			padding-left: 30upx;
			background: url(https://static.xpandago.net/wechat/images/xpa_shuaXing.png) no-repeat left center / 22upx 22upx;
			display: flex;
			// .matter_img{
			// 	display: block;
			// 	margin-right: 20upx;
			// 	width: 24upx;
			// 	height: 24upx;
			// }
			text{
				font-size: 22upx;
				font-weight: 500;
				color: #333333;
				line-height: 22upx;
			}
		}
	}
	.matter_list{
		padding: 20upx 30upx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.matter_list_txt{
			font-size: 24upx;
			font-weight: bold;
			color: #333333;
			line-height: 38upx;
		}
		.matter_list_titleInfo{
			font-size: 20upx;
			font-weight: 500;
			color: #999999;
			line-height: 38upx;
		}
		.matter_list_fr{
			position: relative;
			padding: 16upx 30upx;
			background: #070506;
			border-radius: 30upx;
			text-align: center;
			font-size: 24upx;
			font-weight: 500;
			color: #FEFEFE;
			line-height: 24upx;
			.redCircle{
				position: absolute;
				right: 0;
				top: 0;
				width: 14upx;
				height: 14upx;
				background: #F64D3A;
				border-radius: 50%;
			}
		}
	}
	.foot{
		margin: 18upx 0;
		display: flex;
		flex-wrap: wrap;
		.foot_list{
			width: 158upx;
			height: 90upx;
		}
		.tuan{
			background: url(https://static.xpandago.net/wechat/images/newData_zjmx@2x.png) no-repeat center/100% 100%;
			margin-right: 18upx;
		}
		.zi{
			background: url(https://static.xpandago.net/wechat/images/newData_fsxq@2x.png) no-repeat center/100% 100%;
			margin-right: 18upx;
		}
		.fen{
			background: url(https://static.xpandago.net/wechat/images/newData_tdyj@2x.png) no-repeat center/100% 100%;
			margin-right: 18upx;
		}
		.ding{
			background: url(https://static.xpandago.net/wechat/images/newData_ddmx@2x.png) no-repeat center/100% 100%;
		}
		.jiang{
			background: url(https://static.xpandago.net/wechat/images/tdjjgl@2x.png) no-repeat center/100% 100%;
			margin-top: 20upx;
		}
	}
	.zhao{
		position: fixed;
		left: 0;
		top: 0;
		bottom: 0;
		right: 0;
		z-index: 9;
		background-color: #000000;
		opacity: 0.5;
	}
	.popup{
		position: fixed;
		left: 50%;
		top: 50%;
		transform: translate(-50%,-50%);
		z-index: 10;
		.popup_txt{
			padding: 20rpx 30rpx;
			font-size: 36upx;
			font-weight: bold;
			color: #FFFFFF;
		}
	}
</style>


<template>

	<view class="container">
		<view class="head">
			<view class="time_select">
				<select class="select" v-model="memberType" @change="getCouponSelected">
					<option v-for="(x,i) in directlyList" :key="x.indexId" v-bind:value="x.indexId">{{x.name}}</option>
				</select>
				<view class="time_select_txt">注：不包含当日数据</view>
			</view>
			<view class="head_data">
				<view class="head_list" @tap="openUrl('/pages/newData/newDataItem?index=1&rangeDay=' + memberType,1)">
					<view class="head_list_num">{{obj.income}}</view>
					<view class="head_list_txt">销售收益</view>
				</view>
				<view class="head_list" @tap="openUrl('/pages/newData/newDataItem?index=2&rangeDay=' + memberType,1)">
					<view class="head_list_num">{{obj.orderAmount}}</view>
					<view class="head_list_txt">销售金额</view>
				</view>
				<view class="head_list" @tap="openUrl('/pages/newData/newDataItem?index=3&rangeDay=' + memberType,1)">
					<view class="head_list_num">{{obj.goodsNum}}</view>
					<view class="head_list_txt">销售件数</view>
				</view>
				<view class="head_list" @tap="openUrl('/pages/newData/newDataItem?index=4&rangeDay=' + memberType,1)">
					<view class="head_list_num">{{obj.orderNum}}</view>
					<view class="head_list_txt">销售单数</view>
				</view>
				<view class="head_list" @tap="openUrl('/pages/newData/newDataItem?index=5&rangeDay=' + memberType,1)">
					<view class="head_list_num">{{obj.refundAmount}}</view>
					<view class="head_list_txt">退款金额</view>
				</view>
				<view class="head_list" @tap="openUrl('/pages/newData/newDataItem?index=6&rangeDay=' + memberType,1)">
					<view class="head_list_num">{{obj.refundNum}}</view>
					<view class="head_list_txt">退款件数</view>
				</view>
				<view class="head_list" @tap="openUrl('/pages/newData/newDataItem?index=7&rangeDay=' + memberType,1)">
					<view class="head_list_num">{{obj.registerUserNum}}</view>
					<view class="head_list_txt">注册会员数</view>
				</view>
				<view class="head_list" @tap="openUrl('/pages/newData/newDataItem?index=8&rangeDay=' + memberType,1)">
					<view class="head_list_num">{{obj.orderUserNum}}</view>
					<view class="head_list_txt">下单用户数</view>
				</view>
			</view>
		</view>
		<view class="foot">
			<view class="foot_list fen" @tap="openUrl('/pages/newData/newDataItem?index=9&rangeDay=' + memberType,2)"></view>
			<view class="foot_list tuan" @tap="openUrl('/pages/newData/capital?type=1',3)"></view>
			<view class="foot_list zi" @tap="openUrl('/pages/newData/memberDetail',3)"></view>
			<view class="foot_list ding" @tap="openUrl('/pages/datail/orderDetails',3)"></view>
			<view class="foot_list jiang" @tap="openUrl('/pages/achievememt/bonusManagement',3)"></view>
		</view>
		<view class="matter" v-if="matterList!='' && matterList!=null && matterList!=undefined">
			<view class="matter_title">
				<view class="matter_title_fl">重要事项</view>
				<view class="matter_title_fr" @tap="refresh"><text>刷新</text></view>
			</view>
			<view class="matter_main">
				<view class="matter_list" v-for="(v,i) in matterList" :key="i" @tap="openUrl('/pages/newData/teams?type=1&userId=' + v.userIds,3)">
					<view class="matter_list_fl">
						<view class="matter_list_txt">{{v.title}}</view>
						<view class="matter_list_titleInfo">{{v.titleInfo}}</view>
					</view>
					<view class="matter_list_fr">
						去联络
						<view class="redCircle" v-if="v.readedFlag == 0"></view>
					</view>
				</view>
			</view>
		</view>
		<view class="zhao" v-if="popflag == true"></view>
		<view class="popup" v-if="popflag == true">
			<view class="popup_txt">加载中...</view>
		</view>
	</view>

</template>

<script>
	import api from '@/common/api';
	import webView from '@/common/webView'
	export default {

		components: {},

		data() {

			return {
				popflag:true,
				obj:{},  // 页面数据
				matterList:[],  // 重要事项
				memberType:'7',//选择级别
				directlyList:[
					{name:"最近7天",indexId: '7'},
					{name:"近30天",indexId: '30'},
					{name:"近3个月",indexId: '90'},
					{name:"近1年",indexId: '365'},
				],
			}
		},
		onLoad(){
			// this.token = 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLmtYvor5XpnLgiLCJhdWRpZW5jZSI6ImUxMGFkYzM5NDliYTU5YWJiZTU2ZTA1N2YyMGY4ODNlIiwidXNlcl9pZCI6NzA0NjQsImNyZWF0ZWQiOjE2NDY4ODIxNjI4ODIsImV4cCI6MTY0OTQ3NDE2MiwidXNlcl9ncm91cF9pZCI6MzQ4ODksInBsYXRmb3JtIjpudWxsfQ.UJzfkVok5KZWH4LLBMafpylxd2TWv67KqRPI1QM0L8bxPlNYxgwvhYJTupaPUL6qZHb1DRvqG6Q0kKYqX3LxtQ'
			// // this.token = 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLlhbPns7vpk74xMyIsImF1ZGllbmNlIjoiZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2UiLCJ1c2VyX2lkIjo3ODU1NTQsImNyZWF0ZWQiOjE2NDY5NjIwNzM5NjUsImV4cCI6MTY0OTU1NDA3MywidXNlcl9ncm91cF9pZCI6bnVsbCwicGxhdGZvcm0iOm51bGx9.xjGn5e3CWTGM1iGN-zP-458wD9verwXIYzy7LTXeTC0qc_v1OSmH0AECLrrGwWmo0ZwlVE9XEvapkDtjpxm5Tw'
			// this.agendaNum()
			// this.newDataIndex()
			// let token=this.token
			// uni.setStorageSync('token', token);
			
			
			
			let that=this
			let userStr = navigator.userAgent
			if (userStr.indexOf('Android') !== -1) {
			  that.token = window.Android.getUserToken();
			  let token=that.token
			  uni.setStorageSync('token', token);
			  that.agendaNum()
				that.newDataIndex()
			} else {
			  webView.callhandler('getUserToken', {}, (data) => {
				uni.setStorageSync('token', data);
			    that.token = data;
				that.agendaNum()
				that.newDataIndex()
			  })
			}
		},
		//下拉刷新
		 onPullDownRefresh() {
			//监听下拉刷新动作的执行方法，每次手动下拉刷新都会执行一次
			this.newDataIndex();
			this.agendaNum();
			setTimeout(function () {
				uni.stopPullDownRefresh();  //停止下拉刷新动画
			}, 1000);
		},
		methods: {
			openUrl(url,flagType){
				console.log(flagType)
				if(flagType == 3 || (flagType == 1 && this.obj.shopType != 'storeManager') || (flagType == 2 && this.obj.shopType != 'storeManager')){
					uni.navigateTo({
						url:url
					})
				}else if(flagType == 1 && this.obj.shopType == 'storeManager'){
					uni.showToast({
					 	title: '店长以上等级才可查看店铺排行',
					 	icon: 'none'
					 })
				}else if(flagType == 2 && this.obj.shopType == 'storeManager'){
					uni.navigateTo({
						url:'/pages/newData/brandSales?shopUserId=' + this.obj.shopUserId
					})
				}
				
			},
			getCouponSelected(){
				this.newDataIndex()
			},
			// //返回app
			// openGoods(params){
			// 	this.readed(params.type,params.userIds)
			// 	let userStr = navigator.userAgent
			// 	if (userStr.indexOf('Android') !== -1) {
			// 		let paramsInfo=JSON.parse(JSON.stringify(params))
			// 		 paramsInfo.typeInfo=params.type
			// 		 paramsInfo.type="detailInfo"
			// 		window.Android.showInfoFromJs(JSON.stringify(paramsInfo))
			// 	} else {
			// 		webView.callhandler(
			// 		  "JumpNativePage",
			// 		  {
			// 			Module: "VC_ClientList",
			// 			params: JSON.stringify(params),
			// 		  },
			// 		  (data) => {}
			// 		)
			// 	}
			// },
			// 刷新
			refresh(){
				this.agendaNum()
			},
			// 事项是否已读
			async readed(type,userIds){
				const [err, res] = await api.readed({
					query: {
						type: type,
						userIds: userIds
					},
					header:{
						'token': this.token
					}
				 });
				 if(res.data.code == 0){
				}
			},
			async agendaNum(){
				const [err, res] = await api.agendaNum({
					header:{
						'token': this.token
					}
				 });
				 if(res.data.code == 0){
					 this.matterList = res.data.data
				}else{
					uni.showToast({
					 	title: res.data.msg,
					 	icon: 'none'
					 })
				}
			},
			async newDataIndex(){
				this.popflag = true
				const [err, res] = await api.newDataIndex({
					query:{
						rangeDay:this.memberType
					},
					header:{
						'token': this.token
					}
				 });
				 if(res.data.code == 0){
					 this.popflag = false
					 this.obj = res.data.data
					 // this.obj.shopType = 'serviceProvider'
				}else{
					uni.showToast({
					 	title: res.data.msg,
					 	icon: 'none'
					 })
				}
			},
		},

	}
</script>
